package com.example.ykbboom.universitytransportation.Activity;

import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import com.example.ykbboom.universitytransportation.R;
import com.example.ykbboom.universitytransportation.Util.LogUtil;
import com.example.ykbboom.universitytransportation.Util.NetUtil;
import com.example.ykbboom.universitytransportation.Util.SharedPrefUtil;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class ShowAroundOrderActivity extends BaseActivity {

    private Toolbar mToolBar;
    private ProgressDialog progressDialog;
    private ListView orderListView;
    private SimpleAdapter adapter;
    private List<HashMap<String, String>> listString = new ArrayList<HashMap<String, String>>();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_show_around_order);
        initView();
        NetUtil.showAroundOrderList(progressDialog, SharedPrefUtil.getUserPhone(),SharedPrefUtil.getUserLatlong(),
                String.valueOf(SharedPrefUtil.getCheckDistance()),listString,adapter);
    }

    @Override
    public void initView() {
        super.initView();
        mToolBar = (Toolbar) findViewById(R.id.toolbar_show_around_order);
        setSupportActionBar(mToolBar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setDisplayShowTitleEnabled(false);
        progressDialog = new ProgressDialog(this);
        orderListView = (ListView) findViewById(R.id.show_order_list);
        adapter = new SimpleAdapter(getApplicationContext(), listString, R.layout.place_item_layout,
                new String[] {"startPlace","stopPlace"}, new int[] {R.id.poi_field_id, R.id.poi_value_id});
        orderListView.setAdapter(adapter);
        orderListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                HashMap<String,String>hashMap = listString.get(position);
                NetUtil.getRequestDetail(hashMap.get("gdIdStart"),ShowAroundOrderActivity.this);
            }
        });
        showDialog();
    }
    @Override
    public boolean onOptionsItemSelected(MenuItem item){
        switch (item.getItemId()){
            case android.R.id.home:
                finish();
                break;
        }
        return true;
    }
    /**
     * 显示进度框
     * */
    public void showDialog() {
        progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        progressDialog.setIndeterminate(false);
        progressDialog.setCancelable(true);
        progressDialog.setMessage("正在检索周围请求");
        progressDialog.show();
    }
}
